package com.pisolution.scheduler.runtime.registry;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * 从配置文件中读取注册中心相关配置并在注册中心启动时配置注册中心.
 *
 * @author sora
 * @version 0.1.0
 */
@Component
@PropertySource(value = "classpath:zookeeper.properties")
public class ZookeeperConfig {
    /** 注册中心地址. */
    @Value(value = "${zookeeper.quorum}")
    private String quorum;

    /** 系统数据存储根目录. */
    @Value(value = "${zookeeper.path.root:/scheduler}")
    private String root;

    /** 当前系统所处命名空间. */
    @Value(value = "${zookeeper.cluster.id:/default}")
    private String namespace;

    // -------------------------------------------------------------------------------------------------

    /** 会话超时限制. */
    @Value(value = "${zookeeper.session.timeout:60000}")
    private int sessionTimeout;

    /** 连接超时时间. */
    @Value(value = "${zookeeper.connection.timeout}")
    private int connectionTimeout;

    /** 尝试重连基础时间间隔. */
    @Value(value = "${zookeeper.retry.base.sleep:100}")
    private int baseSleepTime;

    /** 最大重试连接次数. */
    @Value(value = "${zookeeper.retry.max.count:7}")
    private int maxRetries;

    // -------------------------------------------------------------------------------------------------
    //  属性访问
    // -------------------------------------------------------------------------------------------------

    public String getQuorum() {
        return this.quorum;
    }

    public String getRoot() {
        return this.root;
    }

    public String getNamespace() {
        return this.namespace;
    }

    public int getSessionTimeout() {
        return this.sessionTimeout;
    }

    public int getConnectionTimeout() {
        return this.connectionTimeout;
    }

    public int getBaseSleepTime() {
        return this.baseSleepTime;
    }

    public int getMaxRetries() {
        return this.maxRetries;
    }
}
